{extend name="public/main" /}

{block name="body"}
<div class="layui-fluid">
    <form action="{:url('sort')}" method="post">
        <table class="layui-table" style="margin-top: 0;">
            <tr>
                <th style="width: 45px;"><b>ID</b></th>
                <th><b>用户名</b></th>
                <th><b>用户组</b></th>
                <th><b>用户状态</b></th>
                <th style="padding: 0 15px;line-height: 40px;"><b>操作</b>
                    <span style="float: right">
                    <a href="{:url('add')}" data-width="400px" data-height="600px" class="layui-btn layui-btn-sm xn_open" title="添加账号">
                        添加账号
                    </a>
                     <a href=""  class="layui-btn layui-btn-sm" title="刷新">刷新</a>
                </span>
                </th>
            </tr>

            <tbody>
            {foreach name="list" item="vo"}
            <tr>
                <td>{$vo.id}</td>
                <td>{$vo.username}</td>
                <td>
                    {foreach name="vo.auth_group_access" item="v"}
                    <span class="layui-badge layui-bg-orange">{$v}</span>
                    {/foreach}
                </td>
                <td class="layui-form">
                    <input type="checkbox" lay-verify="required" lay-filter="status" name="status" data-id="{$vo.id}"
                           lay-skin="switch" lay-text="正常|禁止" value="1" {if condition="$vo['status'] eq 1"}checked{/if} >
                </td>
                <td>
                    <a href="{:url('groupRule',array('id'=>$vo['id']))}" class="layui-btn layui-btn-xs xn_open" title="分配权限">
                        分配角色
                    </a>
                    <a href="{:url('edit',array('id'=>$vo['id']))}" data-width="400px" data-height="600px" title="{$vo.username}" class="layui-btn layui-btn-normal layui-btn-xs xn_open">
                        <i class="layui-icon layui-icon-edit"></i>修改用户信息
                    </a>
                    {if condition="$vo['id'] neq 1"}
                    <a href="{:Url('delete',array('id'=>$vo['id']))}" title="确认要删除【{$vo.username}】吗？" class="layui-btn layui-btn-danger layui-btn-xs xn_delete">
                        <i class="layui-icon layui-icon-delete"></i>删除
                    </a>
                    {/if}
                </td>
            </tr>
            {/foreach}

            </tbody>
        </table>
    </form>
</div>
{/block}


{block name="js"}
<script>

    layui.form.on('switch(status)', function(data){
        //layer.tips('开关checked：'+ (this.checked ? 'true' : 'false'), data.othis)
        var val = this.checked ? 1 : 0;
        var id = $(this).attr('data-id');
        var url = "{:url('edit')}";
        $.post(url,{id:id,status:val},function (res) {
            console.log(res);
            layer.tips(res.msg, data.othis);
        },'json')
    });
</script>
{/block}